$(document).ready(function(){
	$("#txtcod_perselab").autocomplete({
			source: function(request, response) {
			
				$.ajax({
					url: jQuery.scriptPath +'index.php/Persona/busquedaper/',
					dataType: "json",
					data: request,
					success: function(data) {
						response(data);
					}
				});
			},
			minLength: 2,
			select: function(event, ui) {
				//$(this).data('id', ui.item.id);
				//alert($(this).data("id"));
				$('#hd_cod_pers').val(ui.item.id);
				//alert(ui.item ? ("Selected: " + ui.item.value + " aka " + ui.item.id) : "Nothing selected, input was " + this.value);
			}
		});
		
	$("#txtfech_ing").datepicker({
			showOn: 'button',
			buttonImage: jQuery.scriptPath +'img/calendar.gif',
			buttonImageOnly: true,
			showAnim: 'fadeIn',
			dateFormat: 'yy-mm-dd',
			changeMonth: true,
			changeYear: true,
			showButtonPanel: true
		});
});
function callbackbusmatprima(){
		$(".busmantprima").autocomplete({
			source: function(request, response) {
			
				$.ajax({
					url: jQuery.scriptPath +'index.php/MateriaPrima/busquedajson/',
					dataType: "json",
					data: request,
					success: function(data) {
						response(data);
					}
				});
			},
			minLength: 2,
			select: function(event, ui) {
				//$(this).data('id', ui.item.id);
				//alert($(this).data("id"));
				//$('#hd_cod_pers').val(ui.item.id);
				cell= $(this).parent();
				q=ui.item.id;
                 $('#cod_mateprima', cell).val(q);
      				/*
	      		$.ajax({
		 			dataType: "html",
				 	type: "GET",
				 	url: jQuery.scriptPath +'index.php/Llenarcombos/combocombinahtml/?term='+q,
					beforeSend: function(data){
						$(this).html('<option>Cargando...</option>');
					},
					success: function(requestData){
						//alert(q);
						//alert(requestData);
						//cell = $combo.parent();
						//$('#cod_combin', fila).html('');
						//$(this).html(requestData);
						$('#cod_combin', cell.parent()).html(requestData);
						//$('#result').html("<textarea>"+requestData+"</textarea>");
					},		
					error: function(requestData, strError, strTipoError){											
						$("#result").html("Error " + strTipoError +": " + strError);
					}
				});*/
					$.get(jQuery.scriptPath +'index.php/Llenarcombos/combocombinahtml/?term='+q, function(data) {
						//$(this).html(data);
						$('#cod_combin', cell.parent()).html(data);
					});
				//alert(ui.item ? ("Selected: " + ui.item.value + " aka " + ui.item.id) : "Nothing selected, input was " + this.value);
			}
		});
		/*
		$('.busmantprima').blur(function(){
			$combo = $(this);
			fila = $combo.parent().parent();
			q = $('#cod_mateprima', fila).val();
			//$.get(jQuery.scriptPath +'index.php/Llenarcombos/combocombinahtml/?term='+q, function(data) {
			//	$(this).html(data);
			//});
			
			$.ajax({
	 			dataType: "html",
			 	type: "GET",
			 	url: jQuery.scriptPath +'index.php/Llenarcombos/combocombinahtml/?term='+q,
				beforeSend: function(data){
					$(this).html('<option>Cargando...</option>');
				},
				success: function(requestData){
					//alert(q);
					//alert(requestData);
					//cell = $combo.parent();
					$('#cod_combin', fila).html('');
					//$(this).html(requestData);
					$('#cod_combin', fila).html(requestData);
					$('#result').html("<textarea>"+requestData+"</textarea>");
				},		
				error: function(requestData, strError, strTipoError){											
					$("#result").html("Error " + strTipoError +": " + strError);
				}
			});
		});*/
		//onfocus="$('#result').append('entraste<br>')"
}
ExecActionMante=function (type){
	hdcodigo 		= $('#hdcodigo').val();
	hd_cod_pers 	= $('#hd_cod_pers').val();
	txtfech_ing 	= $('#txtfech_ing').val();
	txtds_obs 		= $('#txtds_obs').val();
	
	st_stado	= '1';
	var arrtable = $("#frmdetallePeco").serialize();
	$.ajax({
 		dataType: "html",
	 	type: "POST",
	 	url: jQuery.scriptPath +'index.php/Pecosa/executemante/',
	 	data: "type="+type
	 			+"&hdcodigo="+hdcodigo
	 			+"&hd_cod_pers="+hd_cod_pers
	 			+"&txtfech_ing="+txtfech_ing
	 			+"&txtds_obs="+txtds_obs
	 			+'&st_stado='+st_stado+"&"+ arrtable,
		beforeSend: function(data){

		},
		success: function(requestData){
			//alert(requestData); 	
			$("#result").html(requestData);
		},		
		error: function(requestData, strError, strTipoError){											
			$("#result").html("Error " + strTipoError +": " + strError);
			//alert("Error " + strTipoError +": " + strError);
		}
	});
}